#pragma once

#include "..\dxstdafx.h"
#include <vector>
#include <string>
#include "Asset.h"
#include "Texture.h"
#include "Shader.h"
#include "ResManager.h"

namespace ds {

class Texture;
class Shader;

class Material : public Asset {

struct TextureEntry {
	ResourceHandle textureHandle;
	int sampler;
	int adressingMode;
	bool used;
};

//typedef std::vector<TextureEntry> TextureEntries;
//typedef std::vector<Shader*> Shaders;
typedef List<ResourceHandle> ShaderHandles;

public:
	Material(const char* name);
	Material(const char* name,const char* textureName);	
	Material(const char* name,const ResourceHandle& textureHandle);	
	~Material();
	void SetAmbient(const Color &color);
	const Color GetAmbient() { return m_D3DMaterial.Ambient; }
	void SetDiffuse(const Color &color);
	const Color GetDiffuse() { return m_D3DMaterial.Diffuse; }
	void SetSpecular(const Color &color, const float power);
	void GetSpecular(Color &_color, float &_power) { _color = m_D3DMaterial.Specular; _power = m_D3DMaterial.Power; }
	void SetEmissive(const Color &color);
	const Color GetEmissive() { return m_D3DMaterial.Emissive; }
	void Set(const Color &color);
	void setAlpha(bool alpha) { m_Alpha = alpha; }
	bool hasAlpha() const { return m_Alpha; }
	float getAlpha() const { return m_D3DMaterial.Diffuse.a; }
	void useLight(bool useLight) { m_UseLight = useLight; }
	const bool lightEnabled() const { return m_UseLight; }
	void Use();
	// texture handling
	void applyTextures();
	Texture* getTexture(int sampler);
	bool hasTextures();
	void replaceTexture(int index,ResourceHandle handle);
	// shader handling
	//void addShader(Shader* shader);
	void addShader(ResourceHandle handle) {
		m_ShaderHandles.append(handle);
	}
	bool hasShaders() const {
		return m_ShaderHandles.num() > 0;
	}
	uint32 getShaderCounter() const {
		return m_ShaderHandles.num();
	}
	//Shader* getShader(int index);
	ResourceHandle& getShaderHandle(uint32 index) {
		return m_ShaderHandles[index];
	}
	//Shader* getShader(const char* name);

private:
	void clear();
	D3DMATERIAL9 m_D3DMaterial;
	//TextureEntries m_TextureEntries;
	//Shaders m_Shaders;
	ShaderHandles m_ShaderHandles;
	bool m_UseLight;
	bool m_Alpha;
	TextureEntry m_Entries[5];
	bool m_UseTextures;
};

};

